#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ == taoyulong2018@gmail.com
# __time__ == 2023/7/14 11:05
# ===========================================
#       题目名称： 73. 矩阵置零
#       题目地址： https://leetcode.cn/problems/set-matrix-zeroes/
#       题目描述： https://note.youdao.com/s/LWYgPSzT
# ===========================================


class Solution:
    def setZeroes(self, matrix):
        """
        Do not return anything, modify matrix in-place instead.
        """
        ZERO_FLAG = "ZERO"
        for x in range(len(matrix)):
            cur_find_zero = False
            for y in range(len(matrix[x])):
                if matrix[x][y] == 0:
                    cur_find_zero = True
                    for i in range(len(matrix)):
                        if matrix[i][y] != 0:
                            matrix[i][y] = ZERO_FLAG
            if cur_find_zero:
                matrix[x] = [ZERO_FLAG for _ in range(len(matrix[x]))]
        print(id(matrix))
        # matrix = [[0 if matrix[i][j] == -1 else matrix[i][j] for j in range(len(matrix[i]))]for i in range(len(matrix))]
        for i in range(len(matrix)):
            for j in range(len(matrix[i])):
                if matrix[i][j] == ZERO_FLAG:
                    matrix[i][j] = 0
        print(id(matrix))
        print(matrix)


if __name__ == '__main__':
    s = Solution()
    # [[1,0,1],[0,0,0],[1,0,1]]
    s.setZeroes(matrix=[[1, 1, 1], [1, 0, 1], [1, 1, 1]])
    # [[0,0,0,0],[0,4,5,0],[0,3,1,0]]
    s.setZeroes(matrix=[[0, 1, 2, 0], [3, 4, 5, 2], [1, 3, 1, 5]])
    # [[0,0,0,0],[0,0,0,4],[0,0,0,0],[0,0,0,3],[0,0,0,0]]
    s.setZeroes(matrix=[[0, 0, 0, 5], [4, 3, 1, 4], [0, 1, 1, 4], [1, 2, 1, 3], [0, 0, 1, 1]])
    # 0005
    # 4314
    # 0114